﻿// The Nova Project by Ken Beckett.
// Copyright (C) 2007-2012 Inevitable Software, all rights reserved.
// Released under the Common Development and Distribution License, CDDL-1.0: http://opensource.org/licenses/cddl1.php

using System.Collections.Generic;
using System.Windows.Media;

using Nova.CodeDOM;

namespace Nova.UI
{
    /// <summary>
    /// The view model for a <see cref="CodeDOM.UnresolvedRef"/>.
    /// </summary>
    public class UnresolvedRefVM : TypeRefBaseVM
    {
        #region /* STATICS */

        internal static void AddViewModelMapping()
        {
            CreateViewModel.Add(typeof(UnresolvedRef),
                delegate(CodeObject codeObject, bool isDescription, Dictionary<CodeObject, CodeObjectVM> dictionary) { return new UnresolvedRefVM((UnresolvedRef)codeObject, dictionary); });
        }

        #endregion

        #region /* CONSTRUCTORS */

        /// <summary>
        /// Create a view model instance for the specified <see cref="CodeDOM.UnresolvedRef"/>.
        /// </summary>
        public UnresolvedRefVM(UnresolvedRef unresolvedRef, Dictionary<CodeObject, CodeObjectVM> dictionary)
            : base(unresolvedRef, true, dictionary)
        { }

        #endregion

        #region /* PROPERTIES */

        /// <summary>
        /// The underlying <see cref="CodeDOM.UnresolvedRef"/> model.
        /// </summary>
        public UnresolvedRef UnresolvedRef
        {
            get { return (UnresolvedRef)CodeObject; }
        }

        #endregion

        #region /* METHODS */

        #endregion

        #region /* RENDERING */

        /// <summary>
        /// Get the brush used to render the UnresolvedRef.
        /// </summary>
        protected override Brush RenderBrush(RenderFlags flags)
        {
            // This can be overloaded with NORMAL_BRUSH for DynamicExpressionRefs.
            return (flags.HasFlag(RenderFlags.InDocComment) ? WARNING_BRUSH : ERROR_BRUSH);
        }

        public override void RenderExpression(CodeRenderer renderer, RenderFlags flags)
        {
            renderer.RenderText((string)UnresolvedRef.Reference, GetMessageBrush(RenderBrush(flags), flags), this);
            RenderTypeArguments(renderer, _typeArgumentVMs, flags, this);
            RenderArrayRanks(renderer, flags);
        }

        public override void RenderToolTip(CodeRenderer renderer, RenderFlags flags)
        {
            RenderType(renderer, CodeObject.GetType(), flags, this);
            RenderMessagesInToolTip(renderer, flags);
        }

        #endregion
    }
}
